//
//  WmcBaseView.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/3/1.
//

import UIKit
import YPBedrock

open class WmcBaseView: UIView {
    // Lifecycle

    public required convenience init() {
        self.init(frame: .zero)
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = .white
        config()
        makeUI()
        bindViewModel() // 反向数据流绑定
        bindViewAction() // 正向数据流绑定
    }

    @available(*, unavailable)
    public required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    deinit {
        WmcLogManager.DebugLog(type: .delloc, log: "View被释放\(self)")
    }

    // Open

    /// 禁用三指键盘撤回
    @available(iOS 13.0, *)
    override open var editingInteractionConfiguration: UIEditingInteractionConfiguration {
        return .none
    }

    open override func layoutSubviews() {
        super.layoutSubviews()
        layoutSubviewsBlock?()
    }
    
    /// 布局完成回调
    open var layoutSubviewsBlock: YPBlock.Empty?
    
    /// 配置数据的地方
    open func config() {}
    /// 创建和布局UI的地方
    open func makeUI() {}

    /// 正向数据流（页面操作的监听）方法放在这里
    open func bindViewAction() {}

    /// 反向数据流（ViewModel的监听）进行数据绑定的放在这里
    open func bindViewModel() {}
}
